package com.victor9ac.mashup.core.adapter;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import com.victor9ac.mashup.api.Commentaries;
import com.victor9ac.mashup.api.Images;
import com.victor9ac.mashup.api.MashupDataType;
import com.victor9ac.mashup.api.travel.Travel;
import com.victor9ac.mashup.contract.CommentsContract;
import com.victor9ac.mashup.contract.ImagesContract;
import com.victor9ac.mashup.contract.TravelContract;
import com.victor9ac.mashup.core.port.MashupJob;
import com.victor9ac.mashup.elasticsearch.annotation.ElasticSearchPersistence;

@Component
public class MashupExecutableJob implements MashupJob {

	@Autowired
	ImagesContract imageJob;
	@Autowired
	CommentsContract commentJob;
	@Autowired
	TravelContract travelJob;
	
	
	//collaborators needed from calculate travel request
	@Autowired
	TravelCalculator travelCalculator;




	@ElasticSearchPersistence(indexType = MashupDataType.IMAGES)
	public Images getImages(String key) {
		return imageJob.getMainImagesByKeyword(key);
	}

	@ElasticSearchPersistence(indexType = MashupDataType.COMMENTS)
	public Commentaries getCommentaries(String key) {
		return commentJob.getFixedComments(key);
	}

	public Travel getTravelByDestination(String key) {
		return travelJob.getTravelInformationGivenADestination(key);
	}

	@ElasticSearchPersistence(indexType = MashupDataType.TRAVELS)
	public Travel getOpenTravel(String from, String to) {

	
		String fromCalculated = travelCalculator.buildTravelFrom(from);
		
		Travel travel = travelJob.getTravelInformationPointToPoint(fromCalculated, to);
		
		travel.setFromCalculated(fromCalculated);
	
		return travel;

	}
	
	
	@ElasticSearchPersistence(indexType = MashupDataType.TRAVELS)
	public Travel getTravel(String from, String to) {
		return travelJob.getTravelInformationPointToPoint(from, to);
	}


	// setters

	public void setImageJob(ImagesContract imageJob) {
		this.imageJob = imageJob;
	}

	public void setCommentJob(CommentsContract commentJob) {
		this.commentJob = commentJob;
	}

	public void setTravelJob(TravelContract travelJob) {
		this.travelJob = travelJob;
	}



}
